<template>
	<view class="page-container">
		<!-- 页面标题 -->
		<view class="page-header">
			<view class="header-content">
				<view class="header-icon">👨‍🎓</view>
				<view class="header-text">
					<text class="header-title">学生管理</text>
					<text class="header-subtitle">管理您的学生信息</text>
				</view>
			</view>
		</view>

		<!-- 添加学生按钮 -->
		<view class="add-button-container">
			<up-button
				icon="plus"
				type="primary"
				size="large"
				@click="handlerAddStudent"
				customStyle="background: linear-gradient(135deg, #6FD719 0%, #5BC016 100%); border: none; border-radius: 25rpx; box-shadow: 0 4px 16px rgba(111, 215, 25, 0.3);"
			>
				<text style="font-weight: 600;">添加学生</text>
			</up-button>
		</view>

		<!-- 学生列表 -->
		<view class="student-list-container">
			<template v-if="bindList.length > 0">
				<view class="student-card" v-for="(item, index) in bindList" :key="item.id">
					<view class="card-header" @click="handlerEditor(item.id)">
						<view class="student-avatar">
							<text class="avatar-text">{{item.name.charAt(0)}}</text>
						</view>
						<view class="student-basic-info">
							<text class="student-name">{{item.name}}</text>
							<view class="student-tags">
								<up-tag
									text="学生"
									type="primary"
									size="mini"
									bgColor="rgba(111, 215, 25, 0.1)"
									color="#6FD719"
									borderColor="transparent"
								></up-tag>
							</view>
						</view>
						<up-icon name="arrow-right" color="#ccc" size="16"></up-icon>
					</view>

					<view class="card-content" @click="handlerEditor(item.id)">
						<view class="info-grid">
							<view class="info-item">
								<up-icon name="bookmark" color="#6FD719" size="14"></up-icon>
								<text class="info-label">学号</text>
								<text class="info-value">{{item.studentId || '----'}}</text>
							</view>
							<view class="info-item">
								<up-icon name="home" color="#4CAF50" size="14"></up-icon>
								<text class="info-label">学校</text>
								<text class="info-value">{{item.schoolName}}</text>
							</view>
							<view class="info-item">
								<up-icon name="grid" color="#FF9800" size="14"></up-icon>
								<text class="info-label">班级</text>
								<text class="info-value">{{item.gradeName}} {{item.classesName}}</text>
							</view>
						</view>
					</view>

					<view class="card-actions">
						<up-button
							type="primary"
							size="small"
							@click.stop="toSelectCombo(item.id)"
							customStyle="background: linear-gradient(135deg, #6FD719 0%, #5BC016 100%); border: none; border-radius: 20rpx; flex: 1; margin-right: 20rpx;"
						>
							<text style="color: #fff; font-weight: 500;">点菜</text>
						</up-button>
						<up-button
							type="default"
							size="small"
							plain
							@click.stop="handlerEditor(item.id)"
							customStyle="border-color: #ddd; color: #666; border-radius: 20rpx; flex: 1;"
						>
							<up-icon name="edit-pen" color="#666" size="14" style="margin-right: 8rpx;"></up-icon>
							<text>编辑</text>
						</up-button>
					</view>
				</view>
			</template>

			<template v-else>
				<view class="empty-container">
					<up-empty
						mode="list"
						text="暂无学生信息"
						textColor="#999"
						iconColor="#ddd"
					></up-empty>
					<view class="empty-tip">
						<text>点击上方按钮添加学生信息</text>
					</view>
				</view>
			</template>
		</view>
	</view>
</template>

<script setup>
	import {
		onMounted,
		ref
	} from 'vue'; 
	import {onShow} from '@dcloudio/uni-app'
	import {
		bindStudent
	} from '../../api/student.js';

	const bindList = ref([])
	
	onShow( async()=>{
		const userInfo = uni.getStorageSync("userInfo")
		bindList.value = await bindStudent(userInfo.id);
	})

	onMounted(async () => {
		const userInfo = uni.getStorageSync("userInfo")
		bindList.value = await bindStudent(userInfo.id);
		
	})

	const handlerEditor = (id) => {
		uni.navigateTo({
			url: '/pages/editStudent/editStudent?id='+id,
		})
	}

	const handlerAddStudent = () => {
		uni.navigateTo({
			url: '/pages/createStudent/createStudent'
		})
	}
	
	const toSelectCombo = (id)=>{
		uni.navigateTo({
			url: '/pages/selectCombo/selectCombo?id='+id,
		})
	}
</script>

<style lang="scss" scoped>
	.page-container {
		background: linear-gradient(180deg, #F8FAFB 0%, #FFFFFF 100%);
		min-height: 100vh;
		padding-bottom: 40rpx;
	}

	/* 页面标题 */
	.page-header {
		background: linear-gradient(135deg, #6FD719 0%, #5BC016 100%);
		padding: 60rpx 30rpx 40rpx;
		border-radius: 0 0 40rpx 40rpx;
		box-shadow: 0 4px 20px rgba(111, 215, 25, 0.2);
	}

	.header-content {
		display: flex;
		align-items: center;
		gap: 20rpx;
	}

	.header-icon {
		font-size: 48rpx;
		width: 80rpx;
		height: 80rpx;
		background: rgba(255, 255, 255, 0.2);
		border-radius: 50%;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.header-text {
		flex: 1;
	}

	.header-title {
		display: block;
		font-size: 36rpx;
		font-weight: 600;
		color: #FFFFFF;
		margin-bottom: 8rpx;
	}

	.header-subtitle {
		font-size: 26rpx;
		color: rgba(255, 255, 255, 0.8);
	}

	/* 添加按钮 */
	.add-button-container {
		padding: 40rpx 30rpx 20rpx;
	}

	/* 学生列表 */
	.student-list-container {
		padding: 0 30rpx;
	}

	.student-card {
		background: linear-gradient(135deg, #FFFFFF 0%, #FAFBFC 100%);
		border-radius: 25rpx;
		margin-bottom: 20rpx;
		box-shadow: 0 4px 16px rgba(0, 0, 0, 0.04);
		border: 1px solid rgba(255, 255, 255, 0.8);
		overflow: hidden;
		transition: all 0.3s ease;
	}

	.student-card:active {
		transform: scale(0.98);
	}

	.card-header {
		display: flex;
		align-items: center;
		padding: 30rpx;
		border-bottom: 1px solid #F5F7FA;
	}

	.student-avatar {
		width: 80rpx;
		height: 80rpx;
		background: linear-gradient(135deg, #6FD719 0%, #5BC016 100%);
		border-radius: 50%;
		display: flex;
		align-items: center;
		justify-content: center;
		margin-right: 20rpx;
		box-shadow: 0 4px 12px rgba(111, 215, 25, 0.3);
	}

	.avatar-text {
		font-size: 32rpx;
		font-weight: 600;
		color: #FFFFFF;
	}

	.student-basic-info {
		flex: 1;
	}

	.student-name {
		font-size: 32rpx;
		font-weight: 600;
		color: #333;
		margin-bottom: 8rpx;
		display: block;
	}

	.student-tags {
		display: flex;
		gap: 10rpx;
	}

	.card-content {
		padding: 30rpx;
	}

	.info-grid {
		display: flex;
		flex-direction: column;
		gap: 20rpx;
	}

	.info-item {
		display: flex;
		align-items: center;
		gap: 12rpx;
		padding: 20rpx;
		background: rgba(111, 215, 25, 0.03);
		border-radius: 15rpx;
		border: 1px solid rgba(111, 215, 25, 0.1);
	}

	.info-label {
		font-size: 26rpx;
		color: #666;
		min-width: 80rpx;
	}

	.info-value {
		font-size: 28rpx;
		color: #333;
		font-weight: 500;
		flex: 1;
	}

	.card-actions {
		display: flex;
		padding: 20rpx 30rpx 30rpx;
		gap: 20rpx;
	}

	/* 空状态 */
	.empty-container {
		background: linear-gradient(135deg, #FFFFFF 0%, #FAFBFC 100%);
		border-radius: 25rpx;
		padding: 80rpx 30rpx;
		text-align: center;
		box-shadow: 0 4px 16px rgba(0, 0, 0, 0.04);
		margin-top: 40rpx;
	}

	.empty-tip {
		margin-top: 20rpx;

		text {
			font-size: 26rpx;
			color: #999;
		}
	}

	/* 动画效果 */
	.student-card {
		animation: slideInUp 0.4s ease-out;
	}

	@keyframes slideInUp {
		from {
			opacity: 0;
			transform: translateY(20rpx);
		}
		to {
			opacity: 1;
			transform: translateY(0);
		}
	}
</style>